use crate::src::test::alloc_testing::{alloc_test_set_limit};
use crate::src::src::binary_heap::{binary_heap_new, binary_heap_free, binary_heap_num_entries, binary_heap_insert, binary_heap_pop};
use crate::src::src::compare_int::{int_compare};
use crate::src::test::framework::{run_tests};
use crate::src::struct_and_type::{BinaryHeapType, _BinaryHeap, BinaryHeapValue, BinaryHeap, BinaryHeapCompareFunc, UnitTestFunction};
use ::libc;
extern "C" {
    
    
    
    
    
    
    
    
}
pub const BINARY_HEAP_TYPE_MAX: BinaryHeapType = 1;
pub const BINARY_HEAP_TYPE_MIN: BinaryHeapType = 0;
#[no_mangle]
pub static mut test_array_test_binary_heap: [libc::c_int; 10000] = [0; 10000];
#[no_mangle]
pub unsafe extern "C" fn test_binary_heap_new_free() {
    let mut heap: *mut BinaryHeap = 0 as *mut BinaryHeap;
    let mut i: libc::c_int = 0;
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        heap = binary_heap_new(
            BINARY_HEAP_TYPE_MIN,
            Some(
                int_compare
                    as unsafe extern "C" fn(
                        *mut libc::c_void,
                        *mut libc::c_void,
                    ) -> libc::c_int,
            ),
        );
        binary_heap_free(heap);
        i += 1;
        i;
    }
    alloc_test_set_limit(0 as libc::c_int);
    heap = binary_heap_new(
        BINARY_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    assert!(heap.is_null());
    alloc_test_set_limit(1 as libc::c_int);
    heap = binary_heap_new(
        BINARY_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    assert!(heap.is_null());
}
#[no_mangle]
pub unsafe extern "C" fn test_binary_heap_insert() {
    let mut heap: *mut BinaryHeap = 0 as *mut BinaryHeap;
    let mut i: libc::c_int = 0;
    heap = binary_heap_new(
        BINARY_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        test_array_test_binary_heap[i as usize] = i;
        assert!(binary_heap_insert(
            heap,
            &mut *test_array_test_binary_heap.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as BinaryHeapValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    assert!(binary_heap_num_entries(heap) == 10000 as libc::c_int as libc::c_uint);
    binary_heap_free(heap);
}
#[no_mangle]
pub unsafe extern "C" fn test_min_heap_test_binary_heap() {
    let mut heap: *mut BinaryHeap = 0 as *mut BinaryHeap;
    let mut val: *mut libc::c_int = 0 as *mut libc::c_int;
    let mut i: libc::c_int = 0;
    heap = binary_heap_new(
        BINARY_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        test_array_test_binary_heap[i as usize] = i;
        assert!(binary_heap_insert(
            heap,
            &mut *test_array_test_binary_heap.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as BinaryHeapValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    i = -(1 as libc::c_int);
    while binary_heap_num_entries(heap) > 0 as libc::c_int as libc::c_uint {
        val = binary_heap_pop(heap) as *mut libc::c_int;
        assert!(*val == i + 1 as libc::c_int);
        i = *val;
    }
    assert!(binary_heap_num_entries(heap) == 0 as libc::c_int as libc::c_uint);
    assert!((binary_heap_pop(heap)).is_null());
    binary_heap_free(heap);
}
#[no_mangle]
pub unsafe extern "C" fn test_max_heap_test_binary_heap() {
    let mut heap: *mut BinaryHeap = 0 as *mut BinaryHeap;
    let mut val: *mut libc::c_int = 0 as *mut libc::c_int;
    let mut i: libc::c_int = 0;
    heap = binary_heap_new(
        BINARY_HEAP_TYPE_MAX,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        test_array_test_binary_heap[i as usize] = i;
        assert!(binary_heap_insert(
            heap,
            &mut *test_array_test_binary_heap.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as BinaryHeapValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    i = 10000 as libc::c_int;
    while binary_heap_num_entries(heap) > 0 as libc::c_int as libc::c_uint {
        val = binary_heap_pop(heap) as *mut libc::c_int;
        assert!(*val == i - 1 as libc::c_int);
        i = *val;
    }
    binary_heap_free(heap);
}
#[no_mangle]
pub unsafe extern "C" fn test_out_of_memory_test_binary_heap() {
    let mut heap: *mut BinaryHeap = 0 as *mut BinaryHeap;
    let mut value: *mut libc::c_int = 0 as *mut libc::c_int;
    let mut values: [libc::c_int; 16] = [
        15 as libc::c_int,
        14 as libc::c_int,
        13 as libc::c_int,
        12 as libc::c_int,
        11 as libc::c_int,
        10 as libc::c_int,
        9 as libc::c_int,
        8 as libc::c_int,
        7 as libc::c_int,
        6 as libc::c_int,
        5 as libc::c_int,
        4 as libc::c_int,
        3 as libc::c_int,
        2 as libc::c_int,
        1 as libc::c_int,
        0 as libc::c_int,
    ];
    let mut i: libc::c_int = 0;
    heap = binary_heap_new(
        BINARY_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    alloc_test_set_limit(0 as libc::c_int);
    i = 0 as libc::c_int;
    while i < 16 as libc::c_int {
        assert!(binary_heap_insert(
            heap,
            &mut *values.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as BinaryHeapValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    assert!(binary_heap_num_entries(heap) == 16 as libc::c_int as libc::c_uint);
    i = 0 as libc::c_int;
    while i < 16 as libc::c_int {
        assert!(binary_heap_insert(
            heap,
            &mut *values.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as BinaryHeapValue,
        ) == 0 as libc::c_int);
        assert!(binary_heap_num_entries(heap) == 16 as libc::c_int as libc::c_uint);
        i += 1;
        i;
    }
    i = 0 as libc::c_int;
    while i < 16 as libc::c_int {
        value = binary_heap_pop(heap) as *mut libc::c_int;
        assert!(*value == i);
        i += 1;
        i;
    }
    assert!(binary_heap_num_entries(heap) == 0 as libc::c_int as libc::c_uint);
    binary_heap_free(heap);
}
static mut tests_test_binary_heap: [UnitTestFunction; 6] = unsafe {
    [
        Some(test_binary_heap_new_free as unsafe extern "C" fn() -> ()),
        Some(test_binary_heap_insert as unsafe extern "C" fn() -> ()),
        Some(test_min_heap_test_binary_heap as unsafe extern "C" fn() -> ()),
        Some(test_max_heap_test_binary_heap as unsafe extern "C" fn() -> ()),
        Some(test_out_of_memory_test_binary_heap as unsafe extern "C" fn() -> ()),
        None,
    ]
};
unsafe fn main_0_test_binary_heap(
    mut argc: libc::c_int,
    mut argv: *mut *mut libc::c_char,
) -> libc::c_int {
    run_tests(tests_test_binary_heap.as_mut_ptr());
    return 0 as libc::c_int;
}
pub fn main_test_binary_heap() {
    let mut args: Vec::<*mut libc::c_char> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::core::ptr::null_mut());
    unsafe {
        ::std::process::exit(
            main_0_test_binary_heap(
                (args.len() - 1) as libc::c_int,
                args.as_mut_ptr() as *mut *mut libc::c_char,
            ) as i32,
        )
    }
}
